<!doctype html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="/A0723/include :: header('提现')"/>
</head>

<body>
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 class="mui-title">提现</h1>
</header>
<div class="mui-content">

    <div class="forget_from">
        <div class="mui-input-row">
            <label>提现金额：</label>
            <input type="text" id="money" placeholder="请输入提现金额">
        </div>
        <div class="mui-input-row">
            <label>提现类型：</label>
            <input type="text" value="请选择提现类型" disabled="disabled" id="info">
            <a class="sele_class" href="#pay"></a>
            <i class="iconfont icon-xiala"></i>
        </div>
        <div class="mui-input-row" style="color: #daad68">
           注意： 提现3小时内到账
        </div>
    </div>
    <button type="button" onclick="withdraw()" class="mui-btn mui-btn-blue mui-btn-block mui_btn">确定</button>

    <!-- 充值类型 -->
    <div id="pay" class="mui-popover mui-popover-action mui-popover-bottom" style="display: block;">
        <ul class="mui-table-view font-pay">
            <li class="mui-table-view-cell ptys">
                <a href="#"><i class="iconfont icon-zhifubao"></i><span id="2">usdt</span></a>
            </li>
            <li class="mui-table-view-cell ptys">
                <a href="#"><i class="iconfont icon-zhifubao"></i><span id="3">银行卡</span></a>
            </li>
            <li class="mui-table-view-cell ptys">
                <a href="#"><i class="iconfont icon-zhifubao"></i><span id="1">支付宝</span></a>
            </li>
            <li class="mui-table-view-cell ptys">
                <a href="#"><i class="iconfont icon-weixin1"></i><span id="0">微信</span></a>
            </li>
        </ul>
    </div>
</div>
<th:block th:include="/A0723/include :: footer"/>
<th:block th:include="/A0723/include :: common"/>
<script type="text/javascript">
    $(function () {

    })

    // 选择
    var type = '';
    var info = document.getElementById("info");
    mui('body').on('tap', '.mui-popover-action li.ptys>a', function () {
        var a = this,
            parent;
        //根据点击按钮，反推当前是哪个actionsheet
        for (parent = a.parentNode; parent != document.body; parent = parent.parentNode) {
            if (parent.classList.contains('mui-popover-action')) {
                type = a.childNodes[1].id
                console.log(type)
                break;
            }
        }
        //关闭actionsheet
        mui('#' + parent.id).popover('toggle');
        info.value = a.childNodes[1].innerHTML
    })


    let data = {}
    //验证
    function validateWithdraw() {
        let money = $("#money").val();
        if (money == null || money === '') {
            mui.toast('请输入充值金额', {duration: 'long', type: 'div'})
            return
        } if (type == null || type === '') {
            mui.toast('请输入提现方式', {duration: 'long', type: 'div'})
            return
        }
        data.money = money;
        data.type = type;

        return true;
    }

    //提现
    function withdraw() {
        if (validateWithdraw()) {
            mui.ajax(ctx+'front/withdraw', {
                data: data,
                dataType: 'json',//服务器返回json格式数据
                type: 'post',//HTTP请求类型
                timeout: 10000,//超时时间设置为10秒；
                headers: {'Content-Type': 'application/json'},
                success: function (res) {
                    //服务器返回响应，根据响应结果，分析是否登录成功；
                    mui.toast(res.msg, {duration: 'long', type: 'div'})
                    setInterval(function () {
                       if(res.code ==500&&res.msg=='收款资料不完善，不能提现！' ){
                           window.location.href = ctx+'front/toProfile'
                       }
                       if(res.code == 0 ){
                           window.location.href = ctx+'front/toMine'
                       }
                    },2000)

                },
                error: function (xhr, type, errorThrown) {
                    //异常处理；
                    console.log(type);
                }
            });
        }
    }
</script>
</body>

</html>
